package dbConnection;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Database {
	
	
	
	public Connection con;
	
	
	public void connect() throws Exception {
		
		if(con != null) return;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/library";
			con = DriverManager.getConnection(url, "Library", "Password");
		} catch (Exception e) {
			throw new Exception("Driver not found");
		}
	       				
	}	

	
	public void disconnect() {
		if(con != null) {
			try {
				con.close();
			} catch (SQLException e) {
				System.out.println("Can't close connection");
			}
		}
	}	
}
